package View;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextPane;
import javax.swing.table.DefaultTableCellRenderer;

import Controller.DeleteAccount;
import Controller.ViewSwitcher;

import javax.swing.table.DefaultTableModel;

import java.sql.Date;

@SuppressWarnings("serial")
public class PanelAccountDetail extends JPanel{

	private static PanelAccountDetail single;
	
	private JButton JBoverzicht = new JButton("terug");
	private JButton NewButton = new JButton("New Transaction");
	private JButton JBdelete = new JButton("delete");
	
	private JLabel formName = new JLabel("overzicht van REKENINGNAAM ");
	private JLabel JLaccnummer = new JLabel("Accounnummer(iBan)");
	private JLabel JLtype = new JLabel("Type");
	private JLabel JLName = new JLabel("Name");
	private JLabel JLrente = new JLabel("Intrests");
	private JLabel JLbalance = new JLabel("Balance");
	
	private JTextPane TPaccnummer = new JTextPane();
	private JTextPane TPtype = new JTextPane();
	private JTextPane TPName = new JTextPane();
	private JTextPane TPrente = new JTextPane();
	private JTextPane TPbalance = new JTextPane();
	
	private JTable table;



	
	public PanelAccountDetail(){
		
		setLayout(null);
		setBounds(140, 0, 860, 725);
		
		formName.setBounds(300, 5, 300, 30);
		
	    JLaccnummer.setBounds(15, 40, 150, 20);
	    JLtype.setBounds(15, 110, 150, 20);
	    JLName.setBounds(15, 180, 150, 20);
	    JLrente.setBounds(15, 250, 150, 20);
	    JLbalance.setBounds(15, 320, 150, 20);
	    
	    TPaccnummer.setBounds(15, 60, 200, 25);
	    TPtype.setBounds(15, 130, 200, 25);
	    TPName.setBounds(15, 200, 200, 25);
	    TPrente.setBounds(15, 270, 200, 25);
	    TPbalance.setBounds(15, 340, 200, 25);

	    NewButton.setBounds(610, 650, 150, 25);
	    JBoverzicht.setBounds(450, 650, 150, 25);
	    JBdelete.setBounds(290, 650, 150, 25);
	    
	    
	    
	    TPaccnummer.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	    TPtype.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	    TPName.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	    TPrente.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	    TPbalance.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	    
	    TPaccnummer.setEditable(false);
	    TPtype.setEditable(false);
	    TPName.setEditable(false);
	    TPrente.setEditable(false);
	    TPbalance.setEditable(false);




	    
	    formName.setForeground(Color.blue);
	    formName.setFont(new Font("Serif", Font.BOLD, 20));
  
	    JBoverzicht.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				PanelHolder mf = PanelHolder.getInstance();
				mf.remove(PanelAccountDetail.getInstance());
				mf.add(PanelAccountView.getInstance());
				mf.repaint();
				mf.validate();
				}});  
	    NewButton.setActionCommand("NewTransaction");
	    NewButton.addActionListener(new ViewSwitcher());
	    JBdelete.setActionCommand("deleteAccount");
	    JBdelete.addActionListener(new DeleteAccount());
	      
	      add(formName);	
	      
	      add(JBoverzicht);
	      add(NewButton);
	      add(JBdelete);
	      
	      add(JLaccnummer);
	      add(JLtype);	      
	      add(JLName);	      
	      add(JLrente);	      
	      add(JLbalance);
	      
	      add(TPaccnummer);
	      add(TPbalance);
	      add(TPName);
	      add(TPrente);
	      add(TPtype);
	  	TransactionTableModel jtm = new TransactionTableModel();
	  	table = new JTable(new DefaultTableModel(
	  		new Object[][] {
	  		},
	  		new String[] {
	  			"Nr", "Date", "Saldo", "Bij/Af"
	  		}
	  	) {
	  		Class[] columnTypes = new Class[] {
	  			Integer.class, Date.class, Integer.class, String.class
	  		};
	  		public Class getColumnClass(int columnIndex) {
	  			return columnTypes[columnIndex];
	  		}
	  		boolean[] columnEditables = new boolean[] {
	  			false, false, false, false
	  		};
	  		public boolean isCellEditable(int row, int column) {
	  			return columnEditables[column];
	  		}
	  	});
	  	
	  	table.setLocation(50, 0);


	  	table.setAutoCreateRowSorter(true);
	  	table.setBackground(Color.BLACK);
		table.setOpaque(false);
		table.setShowGrid(false);
		((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class))
				.setOpaque(false);
					
		JScrollPane scrollPane = new JScrollPane(table);
		scrollPane.setLocation(260,40);
		
		scrollPane.setSize(500, 600);
		scrollPane.setOpaque(false);
		scrollPane.getViewport().setOpaque(false);
		setOpaque(false);
		
		add(scrollPane);	
	}
	

	public static PanelAccountDetail getInstance() {
		if(single == null){
			single = new PanelAccountDetail();
		}
		return single;
	}
	
	public static void selfDestroy(){
		single = null;
	}
}
